package com.ztomorrow.ying_cun_plus.manager;

import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import static com.ztomorrow.ying_cun_plus.constant.author.SystemConstant.BOOK_ID_DIRECT;
import static com.ztomorrow.ying_cun_plus.constant.author.SystemConstant.UPDATE_ROUTING_KEY;

@Component
@RequiredArgsConstructor
public class AmqpMsgManager {

    private final AmqpTemplate amqpTemplate;

    public void sendBookChangeMsg(Long bookId) {
        sendAmqpMessage(BOOK_ID_DIRECT, UPDATE_ROUTING_KEY, bookId);
    }

    public void sendBookChangeMsg(String exchange,String routingKey, Long bookId) {
        sendAmqpMessage(exchange, routingKey, bookId);
    }

    private void sendAmqpMessage(String exchange,String routingKey,Long bookId) {
        amqpTemplate.convertAndSend(exchange, routingKey, bookId);
    }
}
